﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StoreBatchApprove.aspx.cs" Inherits="H2.NET.Web.Pages.SMD.StoreBatchApprove" %>

<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="NPOI.SS.Formula.Functions" %>
<%@ Register Src="../../Controls/DwzAssessment.ascx" TagName="DwzAssessment" TagPrefix="uc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
<head runat="server">
    <title>授权号批量发放</title>
    <link href="../../Resource/Css/Style.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/jBox/Blue/jbox.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/skins/Gray2014/css/all.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/LigeruiExtend.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/JqueryUI/css/smoothness/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/qtip/jquery.qtip.min.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/Css/validform.css" rel="stylesheet" type="text/css" />
    <script src="../../Resource/dwz/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Resource/Js/Common.js" type="text/javascript"></script>
    <script src="../../Resource/jBox/jquery.jBox-2.3.min.js" type="text/javascript"></script>
    <script src="../../Resource/jBox/jquery.jBox-zh-CN.js" type="text/javascript"></script>
    <script src="../../Resource/LigerUI/js/ligerui.all.js" type="text/javascript"></script>
    <script src="../../Resource/JqueryUI/js/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script>
    <script src="../../Resource/qtip/jquery.qtip.min.js" type="text/javascript"></script>
    <script src="../../Resource/Js/Validform_v5.3.2.js" type="text/javascript"></script>

    <style type="text/css">
        #dialog-form { font-size: 62.5%; }
        #dialog-form label { width: 100px; display: inline-block; font-weight: 700; text-align: right; }
        #dialog-form input.text { margin-bottom: 12px; width: 180px; padding: .4em; }
        #dialog-form fieldset { padding: 0; border: 0; margin-top: 15px; }
        #dialog-form fieldset ul li { display: inline-block; width: 330px; float: left; height: 40px; line-height: 40px; }
        #ass_table th { width:15%; }
        #ass_table td { width:85%; }
        .qtip-width { max-width:600px; }
    </style>
    <script type="text/javascript">
        var semValue = [];
        var selected;
        var storegrid;
        $(function () {
            storegrid = $("#storegrid").ligerGrid({
                columns: [
                    { display: '授权号', name: 'AuthID', width: 100 },
                    { display: '门店名称', name: 'StoreName', width: 160, align: 'left' },
                    { display: '门店类型', name: 'StoreType', width: 100 },
                    { display: '渠道', name: 'Channel', width: 100 },
                    { display: '区域', name: 'AreaName', width: 100 },
                    { display: '省份', name: 'ProvinceName', width: 100 },
                    { display: '城市', name: 'CityName', width: 100 },
                    {
                        display: '门店地址', name: 'Address', width: 200, align: 'left',
                        render: function (rowdata, rowindex, value) {
                            if (rowdata.Sem > 20) {
                                var province = rowdata.ProvinceName;
                                var city = rowdata.CityName;
                                var address = rowdata.Address;
                                var span = "<span province='" + province + "' city='" + city + "' style='color:#FF3366;cursor:pointer'>" + address + "</span>";
                                return span;
                            } else {
                                return rowdata.Address;
                            }
                        }
                    },
                    { display: '门店联络人', name: 'ContractPerson', width: 150 },
                    { display: '联络电话', name: 'Telephone', width: 100 }
                ],
                width: '100%', height: '65%', usePager: false, checkbox: true,
                // 设置数据源
                dataAction: 'server', url: '<%=Page.ResolveUrl("~/Pages/SMD/AjaxTools/Handler.ashx?action=get_store&ids=" + ids)%>', rownumbers: true,
                onDblClickRow: function (data, rowindex, rowobj) {
                    $("#dialog-form input[name='ID']").val(data.ID);
                    $("#dialog-form input[name='AuthID']").val(data.AuthID);
                    $("#dialog-form input[name='StoreName']").val(data.StoreName);
                    $("#dialog-form input[name='Address']").val(data.Address);
                    $("#dialog-form input[name='ContractPerson']").val(data.ContractPerson);
                    $("#dialog-form input[name='Telephone']").val(data.Telephone);

                    $("#dialog-form select[name='StoreType']").val(data.StoreType);
                    $("#dialog-form select[name='AreaName']").val(data.AreaName);
                    $("#dialog-form select[name='Channel']").val(data.Channel);
                    initProvince($("#AreaName"),
                        // 初始化省份、城市
                        function () {
                            $("#dialog-form select[name='ProvinceName']").val(data.ProvinceName);
                            initProvince($("#ProvinceName"),
                                function () {
                                    $("#dialog-form select[name='CityName']").val(data.CityName)
                                });
                        });

                    selected = rowobj;

                    $("#dialog-form").dialog("open");
                },
                onAfterShowData: function (currentData) {
                    initAddressTip("span[province]");
                }
            });
            
            /* 弹窗修改 st */
            $("#dialog-form").dialog({
                autoOpen: false,
                height: 400,
                width: 700,
                modal: true,
                buttons: {
                    "提交数据": function () {
                        // todo:数据验证
                        
                        // 更新grid数据
                        var $form = $('<form></form>');
                        $form.append($("#dialog-form").clone());
                        var jsonStr = formatJson($form.serializeArray());
                        storegrid.updateRow(selected, jQuery.parseJSON(jsonStr));

                        $("#dialog-form").dialog("close");
                    },
                    "关闭窗口": function () {
                        $(this).dialog("close");
                    }
                }
            });
            /* 弹窗修改 ed */
        });

        /* 相似地址列表 st */
        function initAddressTip(obj) {
            $(obj).qtip({
                content: {
                    text: function (event, api) {
                        var province = $(this).attr("province");
                        var city = $(this).attr("city");
                        var address = $(this).text();
                        $.ajax({
                            url: '<%=Page.ResolveUrl("~/pages/smd/store.aspx?action=filterStore&province=")%>' + $(this).attr("province") + "&city=" + $(this).attr("city") + "&address=" + $(this).text(),
                            dataType: "json",
                        }).then(function (json) {
                            var rst = json.navTabId.split("|");
                            var content = "";
                            for (var i = 0; i < rst.length; i++) {
                                if (rst[i]) {
                                    var list = rst[i].split(",");
                                    var html = "<tr>";
                                    for (var j = 0; j < list.length; j++) {
                                        html += "<td style='text-align:center'>" + list[j] + "</td>";
                                    }
                                    html += "</tr>";
                                    content += html;
                                }
                            }
                            $("#store_list_tbody").html(content);

                            api.set('content.text', $("#store_list").html());
                        }, function (xhr, status, error) {
                            api.set('content.text', status + ': ' + error);
                        });

                        return '加载中...';
                    }
                },
                hide: {
                    fixed: true,
                    delay: 300
                },
                position: {
                    my: 'top center',
                    at: 'bottom center'
                },
                style: 'qtip-width'
            });
        }
        /* 相似地址列表 ed */

        /* 省份、城市 st */
        function initProvince(arg, callback) {
            var val = $(arg).val();
            var id = $(arg).attr("id");
            if ($.trim(val)) {
                $.ajax({
                    type: 'POST',
                    url: '<%=Page.ResolveUrl("~/pages/smd/store.aspx?action=initProvince")%>',
                    data: { ar: val, type: (id == "ProvinceName" ? "province" : "city") },
                    dataType: "json",
                    cache: false,
                    success: function (json) {
                        var rst = json.navTabId.split("|");
                        var html = "";
                        for (var i = 0; i < rst.length; i++) {
                            if (rst[i]) {
                                var list = rst[i].split(",");
                                html += "<option value='" + list[0] + "'>" + list[1] + "</option>";
                            }
                        }
                        if (id == "ProvinceName") {
                            $("#CityName").find("option:gt(0)").remove().end().append(html);

                        }
                        else {
                            $("#ProvinceName").find("option:gt(0)").remove().end().append(html);
                            $("#CityName").find("option:gt(0)").remove();
                        }

                        if (jQuery.isFunction(callback)) {
                            callback();
                        }
                    }
                });
            }
            else {
                if (id == "ProvinceName") {
                    $("#CityName").find("option:gt(0)").remove();
                }
                else {
                    $("#ProvinceName").find("option:gt(0)").remove();
                    $("#CityName").find("option:gt(0)").remove();
                }
            }
        }
        /* 省份、城市 ed */

        /* 格式化json st */
        function formatJson(jsonObj) {
            var jsonStr = "{";
            $.each(jsonObj, function (i, field) {
                var s = i == 0 ? "\"" : ", \"";
                jsonStr += s + field.name + '":"' + field.value + '" ';
            });
            jsonStr += "}"
            return jsonStr;
        }
        /* 格式化json st */

        /* 提交数据 st */
        function submitData() {
            if (!window.confirm("确认要提交吗？")) {
                return false;
            }

            $.jBox.tip('正在处理，请稍等...', 'loading');

            $.ajax({
                type: 'POST',
                url: '<%=Page.ResolveUrl("~/pages/smd/ajaxtools/handler.ashx")%>?action=set_store&option=' + $("[name='DwzAssessment1$RadOpition']").val() + "&remark=" + $("#DwzAssessment1_Remark").val(),
                data: { data: JSON.stringify(storegrid.getCheckedRows()) },
                success: function (json) {
                    $.jBox.closeTip();
                    if (json == "success") {
                        $.jBox.prompt('操作成功！', '提示', 'info', {
                            closed: function() {
                                closeWin();
                            }
                        });
                    } else {
                        $.jBox.prompt(json, '提示', 'info');
                    }
                }
            });

            return true;
        }
        /* 提交数据 ed */
    </script>


</head>
<body>
    <form runat="server">
        <div class="flowpage">
            <!-- 标题 st -->
            <div class="ffh">
                <table style="width: 100%;">
                    <tr>
                        <td class="logo">
                            <img alt="" src="../../Resource/Images/Logo_AkzoNobel.gif" />
                        </td>
                        <td class="title">
                            <b>授权号批量发放</b>
                        </td>
                        <td class="info" align="left">
                            <div>
                                <label></label>
                            </div>
                            <div>
                                <label></label>
                            </div>
                            <div>
                                <label></label>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <!-- 标题 ed -->

            <div class="flowContent">
                <div id="storegrid" style="margin-bottom:5px;"></div>
                <table id="ass_table" class="formTable" style="margin-top: 10px;">
                    <tbody>
                        <uc:DwzAssessment ID="DwzAssessment1" runat="server" />
                    </tbody>
                </table>
                <div class="flowBtns">
                    <input type="button" class="u-btn" value="提交(Submit)" onclick="return submitData();" />
                    <input type="button" class="u-btn u-btn-c4" value="关闭(Close)" onclick="custom_close()" />
                </div>
            </div>
        </div>

        <!-- 修改页面 st -->
        <div id="dialog-form" title="门店信息修改">
            <fieldset>
                <ul>
                    <li>
                        <label>授权号：</label>
                        <asp:HiddenField ID="StoreID" runat="server" />
                        <asp:TextBox ID="AuthID" runat="server" datatype="*" nullmsg="请选输入授权号" CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    </li>
                    <li>
                        <label>门店名称：</label>
                        <asp:TextBox ID="StoreName" runat="server" datatype="*" nullmsg="请选输入授权号" CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    </li>
                    <li>
                        <label>门店类型：</label>
                        <asp:DropDownList ID="StoreType" runat="server" datatype="*" nullmsg="请选择门店类型"></asp:DropDownList>
                    </li>
                    <li>
                        <label>渠道：</label>
                        <asp:DropDownList ID="Channel" runat="server" datatype="*" nullmsg="请选择渠道"></asp:DropDownList>
                    </li>
                    <li style="width: 100%">
                        <label>区域/省份/城市：</label>
                        <asp:DropDownList ID="AreaName" runat="server" onchange="initProvince(this)" datatype="*" nullmsg="请选择门店区域"></asp:DropDownList>
                        <select id="ProvinceName" runat="server" onchange="initProvince(this)" datatype="*" nullmsg="请选择门店省份">
                            <option value="">==请选择==</option>
                        </select>
                        <select id="CityName" runat="server" datatype="*" nullmsg="请选择门店城市">
                            <option value="">==请选择==</option>
                        </select>
                    </li>
                    <li style="width: 100%">
                        <label>门店地址：</label>
                        <asp:TextBox ID="Address" runat="server" datatype="*" nullmsg="请选输入门店地址" CssClass="text ui-widget-content ui-corner-all" Width="510px"></asp:TextBox>
                    </li>
                    <li>
                        <label>门店联络人：</label>
                        <asp:TextBox ID="ContractPerson" runat="server" datatype="*" nullmsg="请选输入门店联络人" CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    </li>
                    <li>
                        <label>联络电话：</label>
                        <asp:TextBox ID="Telephone" runat="server" datatype="*" nullmsg="请选输入联络电话" CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    </li>
                </ul>
            </fieldset>
        </div>
        <!-- 修改页面 ed -->

        <!-- 相似度地址 -->
        <div class="dialog_content" id="store_list" style="display:none;">
            <table class="htable">
                <thead>
                    <tr>
                        <th>授权号</th>
                        <th>门店名称</th>
                        <th>门店区域</th>
                        <th>门店省份</th>
                        <th>门店城市</th>
                        <th>门店地址</th>
                        <th>联系人</th>
                        <th>状态</th>
                        <th>类型</th>
                        <th>相似度</th>
                    </tr>
                </thead>
                <tbody id="store_list_tbody">
            
                </tbody>
            </table>
        </div>
        <!-- 相似度地址 -->
    </form>
</body>
</html>
